package com.yunji.order.business.delay;

import com.yunji.order.bo.OrderUnFrozenBO;
import com.yunji.order.business.OrderBusiness;
import com.yunji.order.context.convert.OrderConvert;
import com.yunji.order.domain.OrderDO;
import com.yunji.order.emuns.OrderFrozenEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.order.business.pattern
 * @Title: OrderScaleHandler
 * @Description: 订单分润
 * <p>
 * History:
 * Date						Version			Author			Summary
 * ========================================================================
 * 2024-04-20 16:43:35		V1.0			HuaAo		新建类
 */
@Component
public class OrderScaleHandler implements BusinessHandler {
    private static final Logger logs = LoggerFactory.getLogger(OrderScaleHandler.class);

    @Resource
    private OrderBusiness business;

    @Override
    public void process(OrderDO order) {
        logs.info("【延时订单解冻】订单信息:{}", order);
        Long orderId = order.getOrderId();
        OrderDO info = business.getOrderById(orderId);
        OrderUnFrozenBO orderScaleBO = OrderConvert.buildOrderScaleBO(info);
        if (Objects.equals(orderScaleBO.getFrozen(), OrderFrozenEnum.FROZEN.getCode())) {
            logs.info("【延时订单分润】订单{}已解冻", orderId);
            return;
        }
        business.unFrozenScale(orderScaleBO);
        logs.info("【延时订单解冻】订单{}解冻成功", orderId);
    }
}